home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / Technical Documentation / Develop / develop Issue 28 / develop Issue 28 code / MacApp Debugging / TwistDownLists / Substitute MacApp files / UObject.h < prev   
Encoding:
Text File  |  1996-06-21  |  10.4 KB  |  319 lines  |  [TEXT/MPS ]

  1. // UObject.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UOBJECT__
  5. #define __UOBJECT__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __MACAPPTYPES__
  10. #include "MacAppTypes.h"
  11. #endif
  12.  
  13. #ifndef __UCLASSDESC__
  14. #include "UClassDesc.h"
  15. #endif
  16.  
  17. #ifndef __UPOINTEROBJECT__
  18. #include "UPointerObject.h"
  19. #endif
  20.  
  21. // ANSI
  22.  
  23.  
  24. //----------------------------------------------------------------------------------------
  25. // Forward and external class declarations.
  26. //----------------------------------------------------------------------------------------
  27.  
  28. class TObject;
  29. class TStream;
  30. class TDependencySpace;
  31.  
  32. //----------------------------------------------------------------------------------------
  33. // Typedefs
  34. //----------------------------------------------------------------------------------------
  35.  
  36. enum ComparisonResult
  37. {
  38.     kLessThan = -1,
  39.     kEqual = 0,
  40.     kGreaterThan = 1
  41. };
  42.  
  43. typedef long HashValue;
  44.  
  45. //BEGIN Added by C Kopala 6/14/96
  46. #if qDebug
  47. extern long gObjectCount;
  48. extern Boolean gObjectCountingEnabled;
  49. extern Boolean gPrintBaseClassInfo;
  50. extern Boolean gPrintMacAppClassInfo;
  51. extern Boolean gPrintAppClassInfo;
  52. extern Boolean gAppUserFlag1;
  53. extern Boolean gAppUserFlag2;
  54. extern Boolean gAppUserFlag3;
  55. #endif
  56. //END Added by C Kopala 6/14/96
  57. //----------------------------------------------------------------------------------------
  58. // TObject: Definition of the system's root object
  59. //----------------------------------------------------------------------------------------
  60.  
  61. #if    (qDebug || qSym) && defined(__MWERKS__)
  62.     #define qForceClassIDFirstHack    1
  63.     
  64.     // make sure CodeWarrior puts fClassID first, not the vtable
  65.     struct ForceClassIDFirst
  66.     {
  67.         ClassID fClassID;
  68.     };
  69. #else
  70.     #define qForceClassIDFirstHack    0
  71. #endif
  72.  
  73. #if    qForceClassIDFirstHack
  74. class TObject : public ForceClassIDFirst
  75. #else
  76. class TObject
  77. #endif
  78. {
  79.     MA_DECLARE_CLASS;
  80.     
  81. public:
  82.  
  83. #if (qDebug || qSym) && !qForceClassIDFirstHack
  84.     ClassID fClassID;                // Used to do object validation in debug mode.
  85. #endif
  86.  
  87.     //------------------------------------------------------------------------------------
  88.     // Allocate and deallocate.
  89.     //------------------------------------------------------------------------------------
  90.  
  91.     void* operator new(size_t size);
  92.     void operator delete(void* obj);
  93.     
  94.     //------------------------------------------------------------------------------------
  95.     // Initializer and I<Method>.
  96.     //------------------------------------------------------------------------------------
  97.  
  98.     TObject();
  99.         // Constructor
  100.         
  101.     virtual ~TObject();
  102.         // Destructor
  103.     
  104.     void IObject();
  105.         // The ancestral initializer. Should be called in the I<ClassName> chain. i.e.
  106.         // IView -> IEventHandler -> IObject, followed by a called to <ClassName> i.e without
  107.         // the T.
  108.  
  109. //BEGIN Added by C Kopala 6/14/96
  110. #if qDebug
  111.     void PrintConstructorClassInfo();
  112.     void PrintDestructorClassInfo();
  113.     void PrintAppConstructorClassInfo();
  114.     void PrintAppDestructorClassInfo();    
  115.     #endif
  116. //END Added by C Kopala 6/14/96
  117.     //------------------------------------------------------------------------------------
  118.     // Comparison
  119.     //------------------------------------------------------------------------------------
  120.     
  121.     HashValue Hash() const;
  122.  
  123.     virtual Boolean IsSame(const TObject* theObject) const;
  124.         // Does a handle comparison to determine if the objects are in fact the same object
  125.     
  126.     virtual Boolean IsEqual(const TObject* theObject) const;
  127.         // Must be overridden to be useful.  Default implementation calls IsSame
  128.     
  129.     virtual ComparisonResult CompareObject(const TObject* theObject) const;
  130.         // Compares two objects.
  131.         
  132.     virtual Boolean IsGreaterThan(const TObject* obj) const;
  133.     
  134.     virtual Boolean IsLessThan(const TObject* obj) const;
  135.     
  136.     Boolean operator<(const TObject& obj) const;
  137.         // Calls back to IsLessThan.
  138.     
  139.     Boolean operator>(const TObject& obj) const;
  140.         // Calls back to IsGreaterThan.
  141.     
  142.     Boolean operator>=(const TObject& obj) const;
  143.         // Calls back to IsGreaterThan and IsEqual.
  144.     
  145.     Boolean operator<=(const TObject& obj) const;
  146.         // Calls back to IsLessThan and IsEqual.
  147.     
  148.     Boolean operator ==(const TObject& obj) const;
  149.         // Calls back to IsEqual.
  150.         
  151.     Boolean operator !=(const TObject& obj) const;
  152.     
  153.     //------------------------------------------------------------------------------------
  154.     // Change notification
  155.     //------------------------------------------------------------------------------------
  156.  
  157.     void AddDependent(TObject* dependent);
  158.         // Registers the specified object as a dependent of this object in the global
  159.         // dependency space "gMacAppDependencies", so that it will be notified of changes 
  160.         // in this object.
  161.  
  162.     void RemoveDependent(TObject* dependent);
  163.         // Remove the specified object from the list of dependents of this object in 
  164.         // the global dependency space "gMacAppDependencies".
  165.  
  166.     virtual void Changed(ChangeID theChange, TObject* changedBy);
  167.         // Called to inform dependents of this object in the global dependency space 
  168.         // "gMacAppDependencies" that it has been changed. 
  169.         // "theChange" will often contain a command number.
  170.         // "changedBy" will often contain a command object. 
  171.         // Called often, overridden rarely.
  172.  
  173.     virtual void DoUpdate(ChangeID theChange, 
  174.                                 TObject* changedObject,
  175.                                 TObject* changedBy,
  176.                                 TDependencySpace* dependencySpace);
  177.         // Informs this object that an object on which it is dependent in the global
  178.         // dependency space "gMacAppDependencies" has been changed.
  179.         // Called rarely, overridden often.
  180.  
  181.     virtual TDependencySpace* GetDependencySpace();
  182.         // Returns the default dependency space for storing dependents of this object.
  183.         // Returns gMacAppDependencies.
  184.  
  185.     virtual void SetMark(Boolean state);
  186.         // Intended to mark (state=true) or unmark (state=false) this object. Can be used
  187.         // by dependency spaces that require marking, and overridden by objects that store the
  188.         // mark internally. The MacApp dependency spaces do not use this method. 
  189.  
  190.     virtual Boolean IsMarked();
  191.         // Intended to return true if this object is marked. Can be used
  192.         // by dependency spaces that require marking, and overridden by objects that store the
  193.         // mark internally. The MacApp dependency spaces do not use this method. 
  194.  
  195.     virtual void RemoveAllDependencies();
  196.         // Used by TObject::Free to remove all dependency relations in the global
  197.         // dependency space "gMacAppDependencies" which involve this object, either 
  198.         // as notifier or as dependent.
  199.         
  200.     virtual Boolean RemoveDependenciesOnFree();
  201.         // Default is to return true. This will allow us to optimize certain system
  202.         // objects (like TToolBoxEvents).
  203.  
  204.  
  205.  
  206.     //------------------------------------------------------------------------------------
  207.     // Standard signature support.
  208.     //------------------------------------------------------------------------------------
  209.  
  210.     virtual IDType GetStandardSignature();    // override 
  211.         // Returns this class's standard signature.
  212.  
  213.     //------------------------------------------------------------------------------------
  214.     // Stream I/O protocol support.
  215.     //------------------------------------------------------------------------------------
  216.  
  217.     virtual void ReadFrom(TStream* aStream);
  218.     
  219.     virtual void WriteTo(TStream* aStream);
  220.  
  221.  
  222.     //------------------------------------------------------------------------------------
  223.     // Miscellaneous protocol and support methods.
  224.     //------------------------------------------------------------------------------------
  225.  
  226.     virtual TObject* Clone();
  227.         // Makes a duplicate copy of this. The default calls this->ShallowClone, which
  228.         // makes a literal copy of instance variables but does not attempt to clone owned
  229.         // objects. A subclass which owns other objects should override this to clone the
  230.         // owned objects and data structures as well.
  231.  
  232.     virtual void Free();
  233.         // Called to dispose of an object. Gives object a chance to cleanup after itself.
  234.         // Default simply calls this->ShallowFree, which makes no attempt to free instance
  235.         // variables. Should be overridden by any class which allocates space or owns
  236.         // other objects in its instance variables.. Be sure to call Inherited!
  237.  
  238.     ClassID GetClassID() const;
  239.         // Returns the class ID of this.
  240.  
  241.     void GetClassName(ClassName& clName) const;
  242.         // Returns the class name of this.
  243.  
  244.     size_t GetClassSize();
  245.         // Returns the basic instantiation size. i.e. the size in bytes of a newly created
  246.         // object of this class.
  247.  
  248.     const ClassDesc* GetSuperClass();
  249.         // Returns ClassDesc for the immediate superclass. Returns NULL for TObject. If we
  250.         // ever get MI this will have to be an enumerator.
  251.  
  252.     Boolean DescendsFrom(const ClassDesc* classDesc) const;
  253.         // True if my class is a subclass of the class described by ClassDesc.
  254.         
  255.     Boolean IsSameClass(const ClassDesc* classDesc);
  256.         // True if my class is the same as the class described by ClassDesc.
  257.  
  258.     virtual TObject* ShallowClone();
  259.         // Lowest level method for copying an object; should not be overridden except in
  260.         // very unusual cases. Simply calls HandToHand to copy the object data.
  261.  
  262.     virtual void ShallowFree();
  263.         // Lowest level method for freeing an object; should not be overridden except in
  264.         // very unusual cases. Simply calls delete to free the object.
  265.  
  266.     void SubClassResponsibility();
  267.         // Called from methods that MUST be overridden in a subclass. Signals failure.
  268. };
  269.  
  270.  
  271. typedef TObject* TObjectPtr;
  272.  
  273. typedef TObjectPtr* TObjectPtrPtr;
  274.  
  275. typedef TObjectPtrPtr* TObjectPtrHandle;
  276.  
  277. //BEGIN Added by C Kopala 6/14/96
  278. #if qDebug
  279. extern void IncrementObjectCount();
  280. extern void DecrementObjectCount();
  281. extern void PrintObjectCount();
  282. extern void DumpClassInfo();
  283. extern void DisplayMemoryInfo();
  284. extern void InitUDebugGlobals();
  285. #endif
  286. //END Added by C Kopala 6/14/96
  287. //----------------------------------------------------------------------------------------
  288. // INLINES TObject
  289. //----------------------------------------------------------------------------------------
  290.  
  291. inline Boolean TObject::operator==(const TObject& obj) const 
  292.     return (this->IsEqual(&obj));
  293. }
  294.  
  295. inline Boolean TObject::operator!=(const TObject& obj) const 
  296.     return (this->IsEqual(&obj) == FALSE);
  297. }
  298.  
  299. inline Boolean TObject::operator<(const TObject& obj) const
  300.     return  (this->IsLessThan(&obj));
  301. }
  302. inline Boolean TObject::operator>(const TObject& obj) const
  303.     return (this->IsGreaterThan(&obj));
  304. }
  305. inline Boolean TObject::operator>=(const TObject& obj) const
  306.     return (this->IsGreaterThan(&obj) || this->IsEqual(&obj));
  307. }
  308. inline Boolean TObject::operator<=(const TObject& obj) const
  309.     return (this->IsLessThan(&obj) || this->IsEqual(&obj));
  310. }
  311.  
  312. #endif
  313.